package com.ic.controller;

import com.ic.config.OssUtil2;
import com.ic.domain.FaceDetectionResult;
import com.ic.domain.dto.FaceRecognitionDTO;
import com.ic.domain.response.FaceDetectionResponse2;
import com.ic.remote.RemoteTofaceservice;
import com.ic.service.DataingressService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Log4j2
public class DataAccessController {

    @Autowired
    private DataingressService service;

    @Autowired
    private RemoteTofaceservice remoteTofaceservice;

    // 人脸抓拍数据接入
    @PostMapping("/access")
    @Transactional
    public ResponseEntity<?> access(@RequestBody FaceRecognitionDTO data) {
        log.info("开始处理数据接入请求: {}", data);
        try {
            service.access(data);
            log.info("数据接入请求处理成功: {}", data);
            return ResponseEntity.ok().build();
        } catch (Exception e) {
            log.error("数据接入请求处理失败: {}", data, e);
            // 根据实际需求决定是否要返回错误信息或者特定的HTTP状态码
            return ResponseEntity.badRequest().body("数据接入失败");
        }
    }
    // 人脸比对数据接入
    @PostMapping("/compareFaces")
    @Transactional
    public ResponseEntity<?> compareFaces(@RequestBody FaceRecognitionDTO data) {
        log.info("开始处理人脸对比请求: {}", data);
        try {
            service.compareFaces(data);
        } catch (Exception e) {
            log.error("人脸对比请求处理失败: {}", data, e);
            // 根据实际需求决定是否要返回错误信息或者特定的HTTP状态码
            return ResponseEntity.badRequest().body("人脸对比失败");
        }
        return ResponseEntity.ok().build();
    }
}
